package tt.dz.egobus.servicemanager.business.distance;

import tt.dz.egobus.servicemanager.business.point.BusPoint;

import java.util.List;

/**
 * @author Anson
 * @date 17-3-23
 * @name 默认的算法实现类
 * @since 1.0.2
 */
public abstract class AbstractDistanceAlgorithm implements DistanceAlgorithm {


    /**
     * 搜索返回不限制
     */
    public static final double UN_LIMIT = -1D;

    protected List<BusPoint> busPoints;
    protected double x;
    protected double y;
    protected int queueLimit;
    protected double maxDistanceLimit=UN_LIMIT;


    @Override
    public void setBusPoint(List<BusPoint> busPoints) {
        this.busPoints = busPoints;
    }

    @Override
    public void setCurrentPoint(double x, double y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public void setMaxQueueLimit(int queueLimit) {
        this.queueLimit = queueLimit;
    }

    @Override
    public void setMaxDistanceLimit(double maxDistanceLimit) {
        this.maxDistanceLimit = maxDistanceLimit;
    }

    /**
     * @param busPoint bus当前点
     * @author Anson
     * @date 17-3-24
     * @name 判断当前地理位置是否超出了最大距离
     * @since 1.0.2
     */
    public boolean isOverMaxDistanceLimit(BusPoint busPoint) {
        if (this.isUnlimitDistance()) {
            return false;
        }
        double lengthPow = busPoint.distance(this.x, this.y);
        return lengthPow > this.maxDistanceLimit;
    }

    /**
     * @author Anson
     * @date 17-3-24
     * @name 判断当前是否不限制距离
     * @since 1.0.2
     */
    public boolean isUnlimitDistance() {
        return this.maxDistanceLimit == UN_LIMIT;
    }

    /**
     * @author Anson
     * @date 17-3-24
     * @name 判断当前是否限制距离
     * @since 1.0.2
     */
    public boolean isLimitDistance() {
        return this.maxDistanceLimit > 0;
    }


}
